/********************************************************/
/*	Copyright (C) 2016 Gong Li Bin			*/
/*	Project:	GlbCloud			*/
/*	Author:		gong_libin			*/
/*	Date:		2012_01_09			*/
/*	File:		MrTcp.h				*/
/********************************************************/

#ifndef _MRTCP_H
#define	_MRTCP_H

#include "MrNet.h"
#include <netinet/tcp.h>

#define	MR_LINGER			1
#define	MR_LISTEN			20

#define	MR_SHUT_RD			SHUT_RD
#define	MR_SHUT_WR			SHUT_WR
#define	MR_SHUT_RDWR			SHUT_RDWR

class CMrTcp : public CMrNet
{
public:
	CMrTcp();
	virtual ~CMrTcp();

	void MrTcpAccept();
	int MrTcpSetNoDelay();
	int MrTcpInit(char* pszPort);
	void MrTcpShutdown(int iHow);
	int MrTcpConnect(char* pszUrl);
	int MrTcpSetLinger(int iSecond);
	void MrTcpSetFunction(void (*pFunction)(int));
	int MrTcpConnect(struct sockaddr_in* pstAddr);
	int MrTcpConnect(char* pszAddr, char* pszPort);

	virtual int MrNetSend(UCHAR* puszPacket, int iLength);
	virtual int MrNetRecv(UCHAR* puszPacket, int iLength);
	virtual int MrNetSendAll(UCHAR* puszPacket, int iLength);
	virtual int MrNetRecvAll(UCHAR* puszPacket, int iLength);

private:
	void (*m_pFunction)(int);

};

#endif /* _MRTCP_H */
